//
//  shopAddImageView.m
//  BusinessApp
//
//  Created by CccDaxIN on 16/9/29.
//  Copyright © 2016年 macox. All rights reserved.
//

#import "shopAddImageView.h"
#import "SGGenerateQRCodeVC.h"
#import "SGScanningQRCodeVC.h"
#import <AVFoundation/AVFoundation.h>
@implementation shopAddImageView
{
    UIButton *shopImageButton;//添加按钮
    UIButton *deleteImageButton;//删除按钮
    NSInteger imageCount;
    
}

- (id)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        _data_array = [[NSMutableArray alloc]init];
        _dataArray = [[NSMutableArray alloc]init];
        imageCount = 0;
        
        /*
         添加店铺实景button
         */
        NSInteger shopImageTag = 1100;
        for (int i = 0; i <5; i++) {
            shopImageButton = [UIButton buttonWithType:UIButtonTypeCustom];
            [shopImageButton addTarget:self action:@selector(shopImageButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            shopImageButton.tag = shopImageTag++;
            self.recordState = @"NO";
            self.recordPosition = 0;
            shopImageButton.frame = CGRectMake(kScrernWidth/2.5*i,0,kScrernWidth/2.5,100);
            [self addSubview:shopImageButton];
        }
        
        NSInteger deleteImageTag = 1106;
        for (int j = 0; j <5; j++) {
            deleteImageButton = [UIButton buttonWithType:UIButtonTypeCustom];
            [deleteImageButton addTarget:self action:@selector(deleteImageButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            deleteImageButton.tag = deleteImageTag++;
            deleteImageButton.frame = CGRectMake(kScrernWidth/2.5-23+kScrernWidth/2.5*j,5,20,20);
            [self addSubview:deleteImageButton];
        }
        /**判断是发布商品或店铺设置
         */
        if ([[NNSingleton sharedSingleton].setUpORcommodity isEqualToString:@"店铺设置"]) {
            if ([NNSingleton sharedSingleton].shopsData[@"ShopPhoto"] == [NSNull alloc]) {
                shopImageButton = (UIButton *)[self viewWithTag:1100];
                shopImageButton.userInteractionEnabled=YES;
                [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
            }else{
                
                NSLog(@"走在冷风中 %@",[NNSingleton sharedSingleton].shopsData[@"ShopPhoto"]);
                for (NSMutableArray  *array in [NNSingleton sharedSingleton].shopsData[@"ShopPhoto"]) {
                    NSLog(@"key:::: %@", array);
                    [self.data_array addObject:array];
                    [self.dataArray addObject:array];
                }
            }
        }else{
            if ([[NNSingleton sharedSingleton].releasePosition isEqualToString:@"自定义添加"]) {
                [self.data_array removeAllObjects];
                [self.dataArray removeAllObjects];
                
            }else if([[NNSingleton sharedSingleton].releasePosition isEqualToString:@"扫码"]){
                
                if ([NNSingleton sharedSingleton].scanCode[@"ImagePath"] == [NSNull alloc]) {
                    shopImageButton = (UIButton *)[self viewWithTag:1100];
                    shopImageButton.userInteractionEnabled=YES;
                    [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
                }else{
                    NSLog(@"以后的以后 %@",[NNSingleton sharedSingleton].scanCode[@"ImagePath"]);
                    for (NSMutableArray  *array in [NNSingleton sharedSingleton].scanCode[@"ImagePath"]) {
                        NSLog(@"key:::: %@", array);
                        [self.data_array addObject:array];
                        [self.dataArray addObject:array];
                    }
                }
            }else if([[NNSingleton sharedSingleton].releasePosition isEqualToString:@"商品库"]){
                if ([NNSingleton sharedSingleton].commodityImage[@"ImagePath"] == [NSNull alloc]) {
                    shopImageButton = (UIButton *)[self viewWithTag:1100];
                    shopImageButton.userInteractionEnabled=YES;
                    [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
                }else{
                    NSLog(@"以后的以后 %@",[NNSingleton sharedSingleton].commodityImage[@"ImagePath"]);
                    for (NSMutableArray  *array in [NNSingleton sharedSingleton].commodityImage[@"ImagePath"]) {
                        NSLog(@"key:::: %@", array);
                        [self.data_array addObject:array];
                        [self.dataArray addObject:array];
                    }
                }
            }
        }
        NSLog(@"哈哈哈 %lu  %lu",(unsigned long)self.data_array .count,(unsigned long)self.dataArray.count);
        if (_data_array.count == 0) {
            [NNSingleton sharedSingleton].imageArray = @"0";
        }else{
            NSSet *set = [NSSet setWithArray:_data_array];
            NSString *ns=[_data_array componentsJoinedByString:@"@"];
            [NNSingleton sharedSingleton].imageArray = [NSString stringWithFormat:@"%@",ns];
        }
        
        if (self.data_array.count == 0) {
            shopImageButton = (UIButton *)[self viewWithTag:1100];
            if (shopImageButton.tag == 1100) {
                shopImageButton.userInteractionEnabled=YES;
                [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
            }
            deleteImageButton = (UIButton *)[self viewWithTag:1106];
            if (deleteImageButton.tag == 1106) {
                [deleteImageButton setImage:nil forState:UIControlStateNormal];
            }
            shopImageButton = (UIButton *)[self viewWithTag:1101];
            if (shopImageButton.tag == 1101) {
                shopImageButton.userInteractionEnabled=NO;
                [shopImageButton setImage:nil forState:UIControlStateNormal];
                shopImageButton.hidden = YES;
            }
            shopImageButton = (UIButton *)[self viewWithTag:1102];
            if (shopImageButton.tag == 1102) {
                shopImageButton.userInteractionEnabled=NO;
                [shopImageButton setImage:nil forState:UIControlStateNormal];
                shopImageButton.hidden = YES;
            }
            shopImageButton = (UIButton *)[self viewWithTag:1103];
            if (shopImageButton.tag == 1103) {
                shopImageButton.userInteractionEnabled=NO;
                [shopImageButton setImage:nil forState:UIControlStateNormal];
                shopImageButton.hidden = YES;
            }
            shopImageButton = (UIButton *)[self viewWithTag:1104];
            if (shopImageButton.tag == 1104) {
                shopImageButton.userInteractionEnabled=NO;
                [shopImageButton setImage:nil forState:UIControlStateNormal];
                shopImageButton.hidden = YES;
            }
//            shopImageButton = (UIButton *)[self viewWithTag:1105];
//            if (shopImageButton.tag == 1105) {
//                shopImageButton.userInteractionEnabled=NO;
//                [shopImageButton setImage:nil forState:UIControlStateNormal];
//                shopImageButton.hidden = YES;
//            }
        }
        
        if (self.data_array.count == 1) {
            NSString *imageStr = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.data_array objectAtIndex:0]];
            NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStr]];
            shopImageButton = (UIButton *)[self viewWithTag:1100];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:[UIImage imageWithData:data]forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1101];
            shopImageButton.userInteractionEnabled=YES;
            [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1102];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:nil forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1103];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:nil forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1104];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:nil forState:UIControlStateNormal];
            imageCount = 1;
            
        }else if(self.data_array.count == 2){
            NSString *imageStrOne = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.data_array objectAtIndex:0]];
            NSData *dataOne = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrOne]];
            NSString *imageStrTwo = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.data_array objectAtIndex:1]];
            NSData *dataTwo = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrTwo]];
            
            shopImageButton = (UIButton *)[self viewWithTag:1100];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:[UIImage imageWithData:dataOne]forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1101];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:[UIImage imageWithData:dataTwo]forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1102];
            shopImageButton.userInteractionEnabled=YES;
            [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1103];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:nil forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1104];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:nil forState:UIControlStateNormal];

            imageCount = 2;
            
        }else if(self.data_array.count == 3){
            NSString *imageStrOne = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.data_array objectAtIndex:0]];
            NSData *dataOne = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrOne]];
            NSString *imageStrTwo = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.data_array objectAtIndex:1]];
            NSData *dataTwo = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrTwo]];
            NSString *imageStrThree = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.data_array objectAtIndex:2]];
            NSData *dataThree = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrThree]];
            
            shopImageButton = (UIButton *)[self viewWithTag:1100];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:[UIImage imageWithData:dataOne]forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1101];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:[UIImage imageWithData:dataTwo]forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1102];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:[UIImage imageWithData:dataThree]forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1103];
            shopImageButton.userInteractionEnabled=YES;
            [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1104];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:nil forState:UIControlStateNormal];
            imageCount = 3;
            
        }else if(self.data_array.count == 4){
            NSString *imageStrOne = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.data_array objectAtIndex:0]];
            NSData *dataOne = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrOne]];
            NSString *imageStrTwo = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.data_array objectAtIndex:1]];
            NSData *dataTwo = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrTwo]];
            NSString *imageStrThree = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.data_array objectAtIndex:2]];
            NSData *dataThree = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrThree]];
            NSString *imageStrFour = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.data_array objectAtIndex:3]];
            NSData *dataFour = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrFour]];
            
            shopImageButton = (UIButton *)[self viewWithTag:1100];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:[UIImage imageWithData:dataOne]forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1101];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:[UIImage imageWithData:dataTwo]forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1102];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:[UIImage imageWithData:dataThree]forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1103];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:[UIImage imageWithData:dataFour]forState:UIControlStateNormal];
            
            shopImageButton = (UIButton *)[self viewWithTag:1104];
            shopImageButton.userInteractionEnabled=YES;
            [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
            imageCount = 4;
            
        }else if(self.data_array.count == 5){
            NSString *imageStrOne = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.data_array objectAtIndex:0]];
            NSData *dataOne = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrOne]];
            NSString *imageStrTwo = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.data_array objectAtIndex:1]];
            NSData *dataTwo = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrTwo]];
            NSString *imageStrThree = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.data_array objectAtIndex:2]];
            NSData *dataThree = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrThree]];
            NSString *imageStrFour = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.data_array objectAtIndex:3]];
            NSData *dataFour = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrFour]];
            NSString *imageStrFive = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.data_array objectAtIndex:4]];
            NSData *dataFive = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrFive]];
            
            shopImageButton = (UIButton *)[self viewWithTag:1100];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:[UIImage imageWithData:dataOne]forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1101];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:[UIImage imageWithData:dataTwo]forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1102];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:[UIImage imageWithData:dataThree]forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1103];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:[UIImage imageWithData:dataFour]forState:UIControlStateNormal];
            shopImageButton = (UIButton *)[self viewWithTag:1104];
            shopImageButton.userInteractionEnabled=NO;
            [shopImageButton setImage:[UIImage imageWithData:dataFive]forState:UIControlStateNormal];
            imageCount = 5;
        }
        if (_data_array.count == 1) {
            shopImageButton = (UIButton *)[self viewWithTag:1100];
            shopImageButton.userInteractionEnabled=NO;
            
            deleteImageButton = (UIButton *)[self viewWithTag:1106];
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
        }else if (_data_array.count == 2) {
            shopImageButton = (UIButton *)[self viewWithTag:1100];
            shopImageButton.userInteractionEnabled=NO;
            
            shopImageButton = (UIButton *)[self viewWithTag:1101];
            shopImageButton.userInteractionEnabled=NO;
            
            deleteImageButton = (UIButton *)[self viewWithTag:1106];
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
            deleteImageButton = (UIButton *)[self viewWithTag:1107];
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
        }
        else if (_data_array.count == 3) {
            shopImageButton = (UIButton *)[self viewWithTag:1100];
            shopImageButton.userInteractionEnabled=NO;
            
            shopImageButton = (UIButton *)[self viewWithTag:1101];
            shopImageButton.userInteractionEnabled=NO;
            shopImageButton = (UIButton *)[self viewWithTag:1102];
            shopImageButton.userInteractionEnabled=NO;
            
            deleteImageButton = (UIButton *)[self viewWithTag:1106];
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
            deleteImageButton = (UIButton *)[self viewWithTag:1107];
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
            deleteImageButton = (UIButton *)[self viewWithTag:1108];
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
        } else if (_data_array.count == 4) {
            shopImageButton = (UIButton *)[self viewWithTag:1100];
            shopImageButton.userInteractionEnabled=NO;
            
            shopImageButton = (UIButton *)[self viewWithTag:1101];
            shopImageButton.userInteractionEnabled=NO;
            shopImageButton = (UIButton *)[self viewWithTag:1102];
            shopImageButton.userInteractionEnabled=NO;
            shopImageButton = (UIButton *)[self viewWithTag:1103];
            shopImageButton.userInteractionEnabled=NO;
            
            deleteImageButton = (UIButton *)[self viewWithTag:1106];
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
            deleteImageButton = (UIButton *)[self viewWithTag:1107];
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
            deleteImageButton = (UIButton *)[self viewWithTag:1108];
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
            deleteImageButton = (UIButton *)[self viewWithTag:1109];
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
        }
        else if (_data_array.count == 5) {
            shopImageButton = (UIButton *)[self viewWithTag:1100];
            shopImageButton.userInteractionEnabled=NO;
            
            shopImageButton = (UIButton *)[self viewWithTag:1101];
            shopImageButton.userInteractionEnabled=NO;
            shopImageButton = (UIButton *)[self viewWithTag:1102];
            shopImageButton.userInteractionEnabled=NO;
            shopImageButton = (UIButton *)[self viewWithTag:1103];
            shopImageButton.userInteractionEnabled=NO;
            shopImageButton = (UIButton *)[self viewWithTag:1104];
            shopImageButton.userInteractionEnabled=NO;
            
            deleteImageButton = (UIButton *)[self viewWithTag:1106];
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
            deleteImageButton = (UIButton *)[self viewWithTag:1107];
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
            deleteImageButton = (UIButton *)[self viewWithTag:1108];
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
            deleteImageButton = (UIButton *)[self viewWithTag:1109];
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
            deleteImageButton = (UIButton *)[self viewWithTag:1110];
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
        }
        NSLog(@"红研究 %ld",(long)imageCount);
    }
    return self;
}

#pragma mark -- 添加商店实景图
- (void)shopImageButtonAction:(UIButton *)sender{
    switch (sender.tag) {
        case 1100:
            NSLog(@"1");
            self.recordState = @"YES";
            shopImageButton = (UIButton *)[self viewWithTag:1100];
            [self selectPictureUploadMode];
            
            break;
        case 1101:
            NSLog(@"2");
            self.recordState = @"YES";
            shopImageButton = (UIButton *)[self viewWithTag:1101];
            [self selectPictureUploadMode];
            break;
        case 1102:
            NSLog(@"3");
            self.recordState = @"YES";
            shopImageButton = (UIButton *)[self viewWithTag:1102];
            [self selectPictureUploadMode];
            break;
        case 1103:
            NSLog(@"4");
            self.recordState = @"YES";
            shopImageButton = (UIButton *)[self viewWithTag:1103];
            [self selectPictureUploadMode];
            break;
        case 1104:
            NSLog(@"5");
            self.recordState = @"YES";
            shopImageButton = (UIButton *)[self viewWithTag:1104];
            [self selectPictureUploadMode];
            break;
        default:
            break;
    }
}
#pragma mark -- 删除图片
- (void)deleteImageButtonAction:(UIButton *)sender{
    switch (sender.tag) {
        case 1106:{
            NSLog(@"删除1");
            NSLog(@"几个及格：：；%ld",(long)imageCount);
            if (imageCount == 1) {
                imageCount--;
                [_data_array removeObjectAtIndex:0];
                [_dataArray removeObjectAtIndex:0];
                
                shopImageButton = (UIButton *)[self viewWithTag:1100];
                if (shopImageButton.tag == 1100) {
                    shopImageButton.userInteractionEnabled=YES;
                    [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1106];
                if (deleteImageButton.tag == 1106) {
                    [deleteImageButton setImage:nil forState:UIControlStateNormal];
                }
                
                
                shopImageButton = (UIButton *)[self viewWithTag:1101];
                if (shopImageButton.tag == 1101) {
                    [shopImageButton setImage:nil forState:UIControlStateNormal];
                    shopImageButton.hidden = YES;
                }
            }else if (imageCount == 2) {
                imageCount--;
                [_data_array removeObjectAtIndex:0];
                [_dataArray removeObjectAtIndex:0];
                
                NSString *imageStr = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:0]];
                NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStr]];
                if (data == nil) {//当data=nil因为图片是从手机相册里取出的所以赋值方法不一样
                    NSData *data_array = [self.dataArray objectAtIndex:0];
                    shopImageButton = (UIButton *)[self viewWithTag:1100];
                    if (shopImageButton.tag == 1100) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_array]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1100];
                    if (shopImageButton.tag == 1100) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data]forState:UIControlStateNormal];
                    }
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1106];
                if (deleteImageButton.tag == 1106) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
                }
                shopImageButton = (UIButton *)[self viewWithTag:1101];
                if (shopImageButton.tag == 1101) {
                    shopImageButton.userInteractionEnabled=YES;
                    [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"] forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1107];
                if (deleteImageButton.tag == 1107) {
                    [deleteImageButton setImage:nil forState:UIControlStateNormal];
                }
                shopImageButton = (UIButton *)[self viewWithTag:1102];
                if (shopImageButton.tag == 1102) {
                    [shopImageButton setImage:nil forState:UIControlStateNormal];
                    shopImageButton.hidden = YES;
                }
            }else if (imageCount == 3) {
                imageCount--;
                [_data_array removeObjectAtIndex:0];
                [_dataArray removeObjectAtIndex:0];
                
                NSString *imageStrone = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:0]];
                NSData *dataOne = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrone]];
                
                NSString *imageStrTwo = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:1]];
                NSData *dataTwo = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrTwo]];
                
                
                if (dataOne == nil) {
                    NSData *data_arrayOne = [self.dataArray objectAtIndex:0];
                    shopImageButton = (UIButton *)[self viewWithTag:1100];
                    if (shopImageButton.tag == 1100) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_arrayOne]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1100];
                    if (shopImageButton.tag == 1100) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:dataOne]forState:UIControlStateNormal];
                    }
                }
                if (dataTwo == nil) {
                    NSData *data_arrayTwo = [self.dataArray objectAtIndex:1];
                    shopImageButton = (UIButton *)[self viewWithTag:1101];
                    if (shopImageButton.tag == 1101) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_arrayTwo]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1101];
                    if (shopImageButton.tag == 1101) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:dataTwo]forState:UIControlStateNormal];
                    }
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1106];
                if (deleteImageButton.tag == 1106) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1107];
                if (deleteImageButton.tag == 1107) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
                }
                shopImageButton = (UIButton *)[self viewWithTag:1102];
                if (shopImageButton.tag == 1102) {
                    shopImageButton.userInteractionEnabled=YES;
                    [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"] forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1108];
                if (deleteImageButton.tag == 1108) {
                    [deleteImageButton setImage:nil forState:UIControlStateNormal];
                }
                shopImageButton = (UIButton *)[self viewWithTag:1103];
                if (shopImageButton.tag == 1103) {
                    [shopImageButton setImage:nil forState:UIControlStateNormal];
                    shopImageButton.hidden = YES;
                }
            }else if (imageCount == 4) {
                imageCount--;
                [_data_array removeObjectAtIndex:0];
                [_dataArray removeObjectAtIndex:0];
                
                NSString *imageStrone = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:0]];
                NSData *dataOne = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrone]];
                
                NSString *imageStrTwo = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:1]];
                NSData *dataTwo = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrTwo]];
                
                NSString *imageStrThree = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:2]];
                NSData *dataThree = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrThree]];
                
                if (dataOne == nil) {
                    NSData *data_arrayOne = [self.dataArray objectAtIndex:0];
                    shopImageButton = (UIButton *)[self viewWithTag:1100];
                    if (shopImageButton.tag == 1100) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_arrayOne]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1100];
                    if (shopImageButton.tag == 1100) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:dataOne]forState:UIControlStateNormal];
                    }
                }
                if (dataTwo == nil) {
                    NSData *data_arrayTwo = [self.dataArray objectAtIndex:1];
                    shopImageButton = (UIButton *)[self viewWithTag:1101];
                    if (shopImageButton.tag == 1101) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_arrayTwo]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1101];
                    if (shopImageButton.tag == 1101) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:dataTwo]forState:UIControlStateNormal];
                    }
                }
                if (dataThree == nil) {
                    NSData *data_arrayThree = [self.dataArray objectAtIndex:2];
                    shopImageButton = (UIButton *)[self viewWithTag:1102];
                    if (shopImageButton.tag == 1102) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_arrayThree]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1102];
                    if (shopImageButton.tag == 1102) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:dataThree]forState:UIControlStateNormal];
                    }
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1106];
                if (deleteImageButton.tag == 1106) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1107];
                if (deleteImageButton.tag == 1107) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1108];
                if (deleteImageButton.tag == 1108) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
                }
                shopImageButton = (UIButton *)[self viewWithTag:1103];
                if (shopImageButton.tag == 1103) {
                    shopImageButton.userInteractionEnabled=YES;
                    [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"] forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1109];
                if (deleteImageButton.tag == 1109) {
                    [deleteImageButton setImage:nil forState:UIControlStateNormal];
                }
                shopImageButton = (UIButton *)[self viewWithTag:1104];
                if (shopImageButton.tag == 1104) {
                    [shopImageButton setImage:nil forState:UIControlStateNormal];
                    shopImageButton.hidden = YES;
                }
            }else if (imageCount == 5) {
                imageCount--;
                [_data_array removeObjectAtIndex:0];
                [_dataArray removeObjectAtIndex:0];
                NSString *imageStrone = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:0]];
                NSData *dataOne = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrone]];
                
                NSString *imageStrTwo = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:1]];
                NSData *dataTwo = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrTwo]];
                
                NSString *imageStrThree = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:2]];
                NSData *dataThree = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrThree]];
                
                NSString *imageStrFour = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:3]];
                NSData *dataFour = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrFour]];
                
                if (dataOne == nil) {
                    NSData *data_arrayOne = [self.dataArray objectAtIndex:0];
                    shopImageButton = (UIButton *)[self viewWithTag:1100];
                    if (shopImageButton.tag == 1100) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_arrayOne]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1100];
                    if (shopImageButton.tag == 1100) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:dataOne]forState:UIControlStateNormal];
                    }
                }
                if (dataTwo == nil) {
                    NSData *data_arrayTwo = [self.dataArray objectAtIndex:1];
                    shopImageButton = (UIButton *)[self viewWithTag:1101];
                    if (shopImageButton.tag == 1101) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_arrayTwo]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1101];
                    if (shopImageButton.tag == 1101) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:dataTwo]forState:UIControlStateNormal];
                    }
                }
                if (dataThree == nil) {
                    NSData *data_arrayThree = [self.dataArray objectAtIndex:2];
                    shopImageButton = (UIButton *)[self viewWithTag:1102];
                    if (shopImageButton.tag == 1102) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_arrayThree]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1102];
                    if (shopImageButton.tag == 1102) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:dataThree]forState:UIControlStateNormal];
                    }
                }
                if (dataFour == nil) {
                    NSData *data_arrayFour = [self.dataArray objectAtIndex:3];
                    shopImageButton = (UIButton *)[self viewWithTag:1103];
                    if (shopImageButton.tag == 1103) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_arrayFour]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1103];
                    if (shopImageButton.tag == 1103) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:dataFour]forState:UIControlStateNormal];
                    }
                }
                
                deleteImageButton = (UIButton *)[self viewWithTag:1106];
                if (deleteImageButton.tag == 1106) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1107];
                if (deleteImageButton.tag == 1107) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1108];
                if (deleteImageButton.tag == 1108) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1109];
                if (deleteImageButton.tag == 1109) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
                }
                shopImageButton = (UIButton *)[self viewWithTag:1104];
                if (shopImageButton.tag == 1104) {
                    shopImageButton.userInteractionEnabled=YES;
                    [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"] forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1110];
                if (deleteImageButton.tag == 1110) {
                    [deleteImageButton setImage:nil forState:UIControlStateNormal];
                }
                NSLog(@"%lu",(unsigned long)self.data_array.count);
            }
        }
            break;
        case 1107:{
            NSLog(@"删除2");
            if (imageCount == 2) {
                imageCount--;
                [_data_array removeObjectAtIndex:1];
                [_dataArray removeObjectAtIndex:1];
                
                shopImageButton = (UIButton *)[self viewWithTag:1101];
                if (shopImageButton.tag == 1101) {
                    shopImageButton.userInteractionEnabled=YES;
                    [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1107];
                if (deleteImageButton.tag == 1107) {
                    [deleteImageButton setImage:nil forState:UIControlStateNormal];
                }
                shopImageButton = (UIButton *)[self viewWithTag:1102];
                if (shopImageButton.tag == 1102) {
                    [shopImageButton setImage:nil forState:UIControlStateNormal];
                    shopImageButton.hidden = YES;
                }
            }else if (imageCount == 3) {
                imageCount--;
                [_data_array removeObjectAtIndex:1];
                [_dataArray removeObjectAtIndex:1];
                
                NSString *imageStr = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:1]];
                NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStr]];
                if (data == nil) {
                    NSData *data_array = [self.dataArray objectAtIndex:1];
                    shopImageButton = (UIButton *)[self viewWithTag:1101];
                    if (shopImageButton.tag == 1101) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_array]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1101];
                    if (shopImageButton.tag == 1101) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data]forState:UIControlStateNormal];
                    }
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1107];
                if (deleteImageButton.tag == 1107) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1108];
                if (deleteImageButton.tag == 1108) {
                    [deleteImageButton setImage:nil forState:UIControlStateNormal];
                }
                shopImageButton = (UIButton *)[self viewWithTag:1102];
                if (shopImageButton.tag == 1102) {
                    shopImageButton.userInteractionEnabled=YES;
                    [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"] forState:UIControlStateNormal];
                }
                shopImageButton = (UIButton *)[self viewWithTag:1103];
                if (shopImageButton.tag == 1103) {
                    [shopImageButton setImage:nil forState:UIControlStateNormal];
                    shopImageButton.hidden = YES;
                }
            }else if (imageCount == 4) {
                imageCount--;
                [_data_array removeObjectAtIndex:1];
                [_dataArray removeObjectAtIndex:1];
                
                NSString *imageStrOne = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:1]];
                NSData *dataOne = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrOne]];
                
                NSString *imageStrTwo = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:2]];
                NSData *dataTwo = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrTwo]];
                
                if (dataOne == nil) {
                    NSData *data_array = [self.dataArray objectAtIndex:1];
                    shopImageButton = (UIButton *)[self viewWithTag:1101];
                    if (shopImageButton.tag == 1101) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_array]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1101];
                    if (shopImageButton.tag == 1101) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:dataOne]forState:UIControlStateNormal];
                    }
                }
                if (dataTwo == nil) {
                    NSData *data_arrayTwo = [self.dataArray objectAtIndex:2];
                    shopImageButton = (UIButton *)[self viewWithTag:1102];
                    if (shopImageButton.tag == 1102) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_arrayTwo]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1102];
                    if (shopImageButton.tag == 1102) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:dataTwo]forState:UIControlStateNormal];
                    }
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1107];
                if (deleteImageButton.tag == 1107) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1108];
                if (deleteImageButton.tag == 1108) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"] forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1109];
                if (deleteImageButton.tag == 1109) {
                    [deleteImageButton setImage:nil forState:UIControlStateNormal];
                }
                
                shopImageButton = (UIButton *)[self viewWithTag:1103];
                if (shopImageButton.tag == 1103) {
                    shopImageButton.userInteractionEnabled=YES;
                    [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"] forState:UIControlStateNormal];
                }
                shopImageButton = (UIButton *)[self viewWithTag:1104];
                if (shopImageButton.tag == 1104) {
                    [shopImageButton setImage:nil forState:UIControlStateNormal];
                    shopImageButton.hidden = YES;
                }
            }else if (imageCount == 5) {
                imageCount--;
                [_data_array removeObjectAtIndex:1];
                [_dataArray removeObjectAtIndex:1];
                
                NSString *imageStrOne = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:1]];
                NSData *dataOne = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrOne]];
                
                NSString *imageStrTwo = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:2]];
                NSData *dataTwo = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrTwo]];
                
                NSString *imageStrThree = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:3]];
                NSData *dataThree = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrThree]];
                if (dataOne == nil) {
                    NSData *data_arrayOne = [self.dataArray objectAtIndex:1];
                    shopImageButton = (UIButton *)[self viewWithTag:1101];
                    if (shopImageButton.tag == 1101) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_arrayOne]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1101];
                    if (shopImageButton.tag == 1101) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:dataOne]forState:UIControlStateNormal];
                    }
                }
                if (dataTwo == nil) {
                    NSData *data_arrayTwo = [self.dataArray objectAtIndex:2];
                    shopImageButton = (UIButton *)[self viewWithTag:1102];
                    if (shopImageButton.tag == 1102) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_arrayTwo]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1102];
                    if (shopImageButton.tag == 1102) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:dataTwo]forState:UIControlStateNormal];
                    }
                }
                if (dataThree == nil) {
                    NSData *data_arrayThree = [self.dataArray objectAtIndex:3];
                    shopImageButton = (UIButton *)[self viewWithTag:1103];
                    if (shopImageButton.tag == 1103) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_arrayThree]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1103];
                    if (shopImageButton.tag == 1103) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:dataThree]forState:UIControlStateNormal];
                    }
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1107];
                if (deleteImageButton.tag == 1107) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1108];
                if (deleteImageButton.tag == 1108) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"] forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1109];
                if (deleteImageButton.tag == 1109) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"] forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1110];
                if (deleteImageButton.tag == 1110) {
                    [deleteImageButton setImage:nil forState:UIControlStateNormal];
                }
                
                shopImageButton = (UIButton *)[self viewWithTag:1104];
                if (shopImageButton.tag == 1104) {
                    shopImageButton.userInteractionEnabled=YES;
                    [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"] forState:UIControlStateNormal];
                }
                shopImageButton = (UIButton *)[self viewWithTag:1105];
                if (shopImageButton.tag == 1105) {
                    [shopImageButton setImage:nil forState:UIControlStateNormal];
                    shopImageButton.hidden = YES;
                }
            }
        }
            break;
        case 1108:{
            NSLog(@"删除3");
            if (imageCount == 3) {
                imageCount--;
                [_data_array removeObjectAtIndex:2];
                [_dataArray removeObjectAtIndex:2];
                
                shopImageButton = (UIButton *)[self viewWithTag:1102];
                if (shopImageButton.tag == 1102) {
                    shopImageButton.userInteractionEnabled=YES;
                    [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1108];
                if (deleteImageButton.tag == 1108) {
                    [deleteImageButton setImage:nil forState:UIControlStateNormal];
                }
                shopImageButton = (UIButton *)[self viewWithTag:1103];
                if (shopImageButton.tag == 1103) {
                    [shopImageButton setImage:nil forState:UIControlStateNormal];
                    shopImageButton.hidden = YES;
                }
            }else if (imageCount == 4) {
                imageCount--;
                [_data_array removeObjectAtIndex:2];
                [_dataArray removeObjectAtIndex:2];
                
                NSString *imageStr = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:2]];
                NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStr]];
                
                if (data == nil) {
                    NSData *data_array = [self.dataArray objectAtIndex:2];
                    shopImageButton = (UIButton *)[self viewWithTag:1102];
                    if (shopImageButton.tag == 1102) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_array]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1102];
                    if (shopImageButton.tag == 1102) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data]forState:UIControlStateNormal];
                    }
                }
                
                shopImageButton = (UIButton *)[self viewWithTag:1103];
                if (shopImageButton.tag == 1103) {
                    shopImageButton.userInteractionEnabled=YES;
                    [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1108];
                if (deleteImageButton.tag == 1108) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"] forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1109];
                if (deleteImageButton.tag == 1109) {
                    [deleteImageButton setImage:nil forState:UIControlStateNormal];
                }
                shopImageButton = (UIButton *)[self viewWithTag:1104];
                if (shopImageButton.tag == 1104) {
                    [shopImageButton setImage:nil forState:UIControlStateNormal];
                    shopImageButton.hidden = YES;
                }
            }else if (imageCount == 5) {
                imageCount--;
                [_data_array removeObjectAtIndex:2];
                [_dataArray removeObjectAtIndex:2];
                
                NSString *imageStrOne = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:2]];
                NSData *dataOne= [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrOne]];
                NSString *imageStrTwo = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:2]];
                NSData *dataTwo= [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStrTwo]];
                if (dataOne == nil) {
                    NSData *data_array = [self.dataArray objectAtIndex:2];
                    shopImageButton = (UIButton *)[self viewWithTag:1102];
                    if (shopImageButton.tag == 1102) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_array]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1102];
                    if (shopImageButton.tag == 1102) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:dataOne]forState:UIControlStateNormal];
                    }
                }
                if (dataTwo == nil) {
                    NSData *data_arrayTwo = [self.dataArray objectAtIndex:3];
                    shopImageButton = (UIButton *)[self viewWithTag:1103];
                    if (shopImageButton.tag == 1103) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_arrayTwo]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1103];
                    if (shopImageButton.tag == 1103) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:dataTwo]forState:UIControlStateNormal];
                    }
                }
                
                shopImageButton = (UIButton *)[self viewWithTag:1104];
                if (shopImageButton.tag == 1104) {
                    shopImageButton.userInteractionEnabled=YES;
                    [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1108];
                if (deleteImageButton.tag == 1108) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"] forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1109];
                if (deleteImageButton.tag == 1109) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"] forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1110];
                if (deleteImageButton.tag == 1110) {
                    [deleteImageButton setImage:nil forState:UIControlStateNormal];
                }
            }
            
        }
            break;
        case 1109:{
            NSLog(@"删除4");
            if (imageCount == 4) {
                imageCount--;
                [_data_array removeObjectAtIndex:3];
                [_dataArray removeObjectAtIndex:3];
                
                shopImageButton = (UIButton *)[self viewWithTag:1103];
                if (shopImageButton.tag == 1103) {
                    shopImageButton.userInteractionEnabled=YES;
                    [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1109];
                if (deleteImageButton.tag == 1109) {
                    [deleteImageButton setImage:nil forState:UIControlStateNormal];
                }
                shopImageButton = (UIButton *)[self viewWithTag:1104];
                if (shopImageButton.tag == 1104) {
                    [shopImageButton setImage:nil forState:UIControlStateNormal];
                    shopImageButton.hidden = YES;
                }
            }if (imageCount == 5) {
                imageCount--;
                [_data_array removeObjectAtIndex:3];
                [_dataArray removeObjectAtIndex:3];
                
                NSString *imageStr = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,[self.dataArray objectAtIndex:3]];
                NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStr]];
                if (data == nil) {
                    NSData *data_array = [self.dataArray objectAtIndex:3];
                    shopImageButton = (UIButton *)[self viewWithTag:1103];
                    if (shopImageButton.tag == 1103) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data_array]forState:UIControlStateNormal];
                    }
                }else{
                    shopImageButton = (UIButton *)[self viewWithTag:1103];
                    if (shopImageButton.tag == 1103) {
                        shopImageButton.userInteractionEnabled=NO;
                        [shopImageButton setImage:[UIImage imageWithData:data]forState:UIControlStateNormal];
                    }
                }
                shopImageButton = (UIButton *)[self viewWithTag:1104];
                if (shopImageButton.tag == 1104) {
                    shopImageButton.userInteractionEnabled=YES;
                    [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1109];
                if (deleteImageButton.tag == 1109) {
                    [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"] forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1110];
                if (deleteImageButton.tag == 1110) {
                    [deleteImageButton setImage:nil forState:UIControlStateNormal];
                }
            }
        }
            
            break;
        case 1110:{
            NSLog(@"删除5");
            if (imageCount == 5) {
                imageCount--;
                [_data_array removeObjectAtIndex:4];
                [_dataArray removeObjectAtIndex:4];
                
                if (shopImageButton.tag == 1104) {
                    shopImageButton.userInteractionEnabled=YES;
                    [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
                }
                deleteImageButton = (UIButton *)[self viewWithTag:1110];
                if (deleteImageButton.tag == 1110) {
                    [deleteImageButton setImage:nil forState:UIControlStateNormal];
                }
            }
        }
            break;
        default:
            break;
    }
    
    NSLog(@" 转身之间   %lu  %ld",(unsigned long)_data_array.count,(long)imageCount);
    if (_data_array.count == 0) {
        [NNSingleton sharedSingleton].imageArray = @"0";
    }else{
        NSSet *set = [NSSet setWithArray:_data_array];
        NSString *ns=[_data_array componentsJoinedByString:@"@"];
        [NNSingleton sharedSingleton].imageArray = [NSString stringWithFormat:@"%@",ns];
    }
}
#pragma mark -- 选择图片上传方式
- (void)selectPictureUploadMode{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"选择照片" message:@"从相册选取照片或拍照发送" preferredStyle:UIAlertControllerStyleActionSheet];
    
    // 1、 获取摄像设备
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if (device) {
        [alert addAction:[UIAlertAction actionWithTitle:@"相册选取" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            UIImagePickerController *imagePickController = [[UIImagePickerController alloc]init];
            imagePickController.delegate = self;
            imagePickController.allowsEditing = YES;
            imagePickController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            [self.viewController presentViewController:imagePickController animated:YES completion:^{
            }];
        }]];
        [alert addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
            if(authStatus == AVAuthorizationStatusAuthorized){
                NSLog(@"允许状态");
                UIImagePickerController *imagePickController = [[UIImagePickerController alloc]init];
                imagePickController.delegate = self;
                imagePickController.allowsEditing = YES;
                imagePickController.sourceType = UIImagePickerControllerSourceTypeCamera;
                [self.viewController presentViewController:imagePickController animated:YES completion:^{
                }];
            }else if (authStatus == AVAuthorizationStatusDenied){
                NSLog(@"不允许状态，可以弹出一个alertview提示用户在隐私设置中开启权限");
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"未获得授权使用摄像头" message:@"请在iOS“设置”-“隐私”-“相机”中打开" preferredStyle:UIAlertControllerStyleAlert];
                
                [alert addAction:[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    [alert dismissViewControllerAnimated:YES completion:nil];
                }]];
                [self.viewController presentViewController:alert animated:YES completion:nil];
            }
            else if (authStatus == AVAuthorizationStatusNotDetermined)
            {
                NSLog(@"系统还未知是否访问，第一次开启相机时");
                [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
                    //*******************先回主线程
                    if (granted) {
                        //第一次用户接受
                    }else{
                        //用户拒绝
                    }
                }];
            }
        }]];
    } else {
        [alert addAction:[UIAlertAction actionWithTitle:@"相册选取" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            UIImagePickerController *imagePickController = [[UIImagePickerController alloc]init];
            imagePickController.delegate = self;
            imagePickController.allowsEditing = YES;
            imagePickController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            [self.viewController presentViewController:imagePickController animated:YES completion:^{
            }];
        }]];
    }
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        [alert dismissViewControllerAnimated:YES completion:nil];
    }]];
    [self.viewController presentViewController:alert animated:YES completion:nil];}

#pragma mark - UIImagePickerController Delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage *image = info[UIImagePickerControllerOriginalImage];
    [picker dismissViewControllerAnimated:YES completion:nil];
    
    [self verifyIdentifier:image];
}
#pragma mark -- 上传消费凭证接口
-(void)verifyIdentifier:(UIImage *)image {
    
    NSData *dataPostOne = [self resetSizeOfImageData:image maxSize:1024];
    NSString * strOne = [dataPostOne base64EncodedStringWithOptions:kNilOptions];
    
    NSLog(@"图片的tag之：：%ld",(long)shopImageButton.tag);
    if (shopImageButton.tag == 1100) {
        imageCount++;
        shopImageButton.userInteractionEnabled=NO;
        [shopImageButton setImage:[UIImage imageWithData:dataPostOne]forState:UIControlStateNormal];
        [_data_array addObject:strOne];
        [_dataArray addObject:dataPostOne];
        
        //显示添加图标
        shopImageButton = (UIButton *)[self viewWithTag:1101];
        if (shopImageButton.tag == 1101) {
            shopImageButton.userInteractionEnabled=YES;
            [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
            shopImageButton.hidden = NO;
        }
        //显示删除图标
        deleteImageButton = (UIButton *)[self viewWithTag:1106];
        if (deleteImageButton.tag == 1106) {
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
        }
    }else if (shopImageButton.tag == 1101){
        imageCount++;
        [_data_array addObject:strOne];
        [_dataArray addObject:dataPostOne];
        shopImageButton.userInteractionEnabled=NO;
        [shopImageButton setImage:[UIImage imageWithData:dataPostOne]forState:UIControlStateNormal];
        shopImageButton = (UIButton *)[self viewWithTag:1102];
        if (shopImageButton.tag == 1102) {
            shopImageButton.userInteractionEnabled=YES;
            [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
            shopImageButton.hidden = NO;
        }
        //显示删除图标
        deleteImageButton = (UIButton *)[self viewWithTag:1107];
        if (deleteImageButton.tag == 1107) {
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
        }
    }else if (shopImageButton.tag == 1102){
        imageCount++;
        [_data_array addObject:strOne];
        [_dataArray addObject:dataPostOne];
        shopImageButton.userInteractionEnabled=NO;
        [shopImageButton setImage:[UIImage imageWithData:dataPostOne]forState:UIControlStateNormal];
        shopImageButton = (UIButton *)[self viewWithTag:1103];
        if (shopImageButton.tag == 1103) {
            shopImageButton.userInteractionEnabled=YES;
            [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
            shopImageButton.hidden = NO;
        }
        //显示删除图标
        deleteImageButton = (UIButton *)[self viewWithTag:1108];
        if (deleteImageButton.tag == 1108) {
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
        }
    }else if (shopImageButton.tag == 1103){
        imageCount++;
        [_data_array addObject:strOne];
        [_dataArray addObject:dataPostOne];
        shopImageButton.userInteractionEnabled=NO;
        [shopImageButton setImage:[UIImage imageWithData:dataPostOne]forState:UIControlStateNormal];
        shopImageButton = (UIButton *)[self viewWithTag:1104];
        if (shopImageButton.tag == 1104) {
            shopImageButton.userInteractionEnabled=YES;
            [shopImageButton setImage:[UIImage imageNamed:@"添加照片-"]forState:UIControlStateNormal];
            shopImageButton.hidden = NO;
        }
        //显示删除图标
        deleteImageButton = (UIButton *)[self viewWithTag:1109];
        if (deleteImageButton.tag == 1109) {
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
        }
    }else if (shopImageButton.tag == 1104){
        imageCount++;
        [_data_array addObject:strOne];
        [_dataArray addObject:dataPostOne];
        shopImageButton.userInteractionEnabled=NO;
        [shopImageButton setImage:[UIImage imageWithData:dataPostOne]forState:UIControlStateNormal];
        //显示删除图标
        deleteImageButton = (UIButton *)[self viewWithTag:1110];
        if (deleteImageButton.tag == 1110) {
            [deleteImageButton setImage:[UIImage imageNamed:@"删除图片"]forState:UIControlStateNormal];
        }
    }
    NSLog(@" 你的名字   %lu  %ld",(unsigned long)_data_array.count,(long)imageCount);
    
    if (_data_array.count == 0) {
        [NNSingleton sharedSingleton].imageArray = @"0";
    }else{
        NSSet *set = [NSSet setWithArray:_data_array];
        NSString *ns=[_data_array componentsJoinedByString:@"@"];
        [NNSingleton sharedSingleton].imageArray = [NSString stringWithFormat:@"%@",ns];
    }
}

- (NSData *)resetSizeOfImageData:(UIImage *)source_image maxSize:(NSInteger)maxSize{
    //先调整分辨率
    CGSize newSize = CGSizeMake(source_image.size.width, source_image.size.height);
    
    CGFloat tempHeight = newSize.height / 1024;
    CGFloat tempWidth = newSize.width / 1024;
    
    if (tempWidth > 1.0 && tempWidth > tempHeight) {
        newSize = CGSizeMake(source_image.size.width / tempWidth, source_image.size.height / tempWidth);
    } else if (tempHeight > 1.0 && tempWidth < tempHeight){
        newSize = CGSizeMake(source_image.size.width / tempHeight, source_image.size.height / tempHeight);
    }
    UIGraphicsBeginImageContext(newSize);
    [source_image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    //调整大小
    NSData *imageData = UIImageJPEGRepresentation(newImage, 1.0);
    
    NSUInteger sizeOrigin = [imageData length];
    NSUInteger sizeOriginKB = sizeOrigin / 1024;
    if (sizeOriginKB > maxSize) {
        NSData *finallImageData = UIImageJPEGRepresentation(newImage,0.3);
        return finallImageData;
    }
    return imageData;
}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [self.viewController dismissViewControllerAnimated:YES completion:nil];
}
- (void)saveImage:(UIImage *)currentImage withName:(NSString *)imageName {
    NSData *imageData = UIImageJPEGRepresentation(currentImage, 1.f);
    // 获取沙盒目录
    NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
    // 将图片写入文件
    [imageData writeToFile:fullPath atomically:NO];
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
